package org.leumasjaffe.initiativeTracker.entity;

import java.io.PrintStream;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
 * Class for managing and storing information on Player Characters
 * @author Sam Jaffe
 *
 */
@NonNullByDefault
public final class PC extends Character{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5320729699470544670L;
	private String player;
	private int surgeMax;
	private int surgeLeft;
	private int temp = 0;

	public PC() {
		super();
	}

	public PC (int id) {
		super(id);
	}
		
	/**
	 * Restores up to the given amount of health
	 * @param health The amount of health to recover
	 */
	public void recover(int health) {
		int HP = getHp();
		if (HP + health > getMaxHP())
			setHp(getMaxHP());
		else
			setHp(HP + health);
	}

	/**
	 * Uses a healing surge
	 * @param bonus A bonus to health recovered
	 * @return 
	 */
	public int surge(int bonus) {
		this.surgeLeft--;
		recover(getSurgevalue() + bonus);
		return bonus;
	}

	/**
	 * Exports the player's data to the file in the PrintStream
	 * @param out The PrintStream to the file we are writing to
	 */
	@Override
	public void export(PrintStream out) {
		out.println("PLAYER:: " + this.player);
		out.println("SURGES:: " + this.surgeMax + "," + this.surgeLeft + "," + this.temp);
		super.export(out);
	}

	//Getters and setters
	
	public void setPlayer(String player) {
		this.player = player;
	}

	@SuppressWarnings("null")
	public String getPlayer() {
		return this.player;
	}

	public int getSurgevalue() {
		return getMaxHP()/4;
	}

	public void setSurgeMax(int surgeMax) {
		this.surgeMax = surgeMax;
	}

	public int getSurgeMax() {
		return this.surgeMax;
	}

	public void setSurgeLeft(int surgeLeft) {
		this.surgeLeft = surgeLeft;
	}

	public int getSurgeLeft() {
		return this.surgeLeft;
	}

	public void setTemp(int temp) {
		this.temp = temp; //Set the temp HP to our input
		if (this.temp < 0) { //If its negative
			setHp(getHp() + temp); //Deduct it from regular HP and then...
			nullTemp(); //Null it
		}
	}

	public int getTemp() {
		return this.temp;
	}

	public void nullTemp() {
		this.temp = 0;
	}
	
	int playerCode() {
		return (((byte)this.temp << 16)) + (((byte)this.surgeMax << 8)) + ((byte)this.surgeLeft);
	}

}